<template>
	<div class="container">
		<div class="flex-col full">
			<div class="w_full">
				<div class="w_full flex-row-center space-between">
					<el-button link class="back_title" @click="click_back" :icon="Back">返回排班列表</el-button>
				</div>
			</div>
			<div class="flex_1 flex-row comm_border" style="margin-top: 16px">
				<div class="flex-col" style="margin: 24px;">
					<div class="flex-row">
						<div class="user_title_rec"></div>
						<div class="user_title">排班类型</div>
					</div>
					<div class="flex_1 flex-col" style="margin: 16px">
						<div class="flex-row-center" style="margin: 8px 0px">
							<el-button type="primary" style="">新增排班类型</el-button>
						</div>
						<div class="flex_1">
							<el-table :data="data.listScheduleType" border>
								<el-table-column prop="index" label="序号" width="60" />
								<el-table-column prop="scheduleTypeName" label="名称" />
								<el-table-column label="操作" width="120px">
									<template #default="scope">
										<el-button link size="small" @click="click_edit(scope.$index, scope.row)">编辑
										</el-button>
										<el-button link size="small" @click="click_delete(scope.$index, scope.row)">删除
										</el-button>
									</template>
								</el-table-column>
							</el-table>
						</div>
						<el-pagination v-model:current-page="pager1.currentPage" v-model:page-size="pager1.pageSize"
							:page-sizes="[10,20,30,50]" layout="total, sizes, prev, pager, next, jumper"
							:total="pager1.total" @size-change="handleSizeChange"
							@current-change="handleCurrentChange" />
					</div>
				</div>
				<div class="flex_1 flex-col" style="margin: 24px;">
					<div class="flex-row">
						<div class="user_title_rec"></div>
						<div class="user_title">班次</div>
					</div>
					<div class="flex_1 flex-col" style="margin: 16px">
						<div class="flex-row-center" style="margin: 8px 0px">
							<el-button type="primary" style="">新增排班类型</el-button>
						</div>
						<div class="flex_1">
							<el-table :data="data.listScheduleType" border>
								<el-table-column prop="index" label="序号" width="60" />
								<el-table-column prop="scheduleTypeName" label="名称" />
								<el-table-column label="操作" width="120px">
									<template #default="scope">
										<el-button link size="small" @click="click_edit(scope.$index, scope.row)">编辑
										</el-button>
										<el-button link size="small" @click="click_delete(scope.$index, scope.row)">删除
										</el-button>
									</template>
								</el-table-column>
							</el-table>
						</div>
						<el-pagination v-model:current-page="pager1.currentPage" v-model:page-size="pager1.pageSize"
							:page-sizes="[10,20,30,50]" layout="total, sizes, prev, pager, next, jumper"
							:total="pager1.total" @size-change="handleSizeChange"
							@current-change="handleCurrentChange" />
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script setup lang="ts">
	import { onMounted, reactive } from "vue";
	import { Back } from "@element-plus/icons-vue";
	import msg from "@/components/msg";
	import { DictInfoVO } from "@/type/vo/DictInfoVO";
	import { api_getListUser } from "@/request/apis/userApi";
	import { UserQueryDto } from "@/type/dto/UserQueryDto";
	import { UserInfoVO } from "@/type/vo/UserInfoVO";
	import { useRoute } from "vue-router";
	import { DICT_TYPE_LEVEL, DICT_TYPE_POSITION, DICT_TYPE_TITLE } from "@/constants/Constants_DictType";
	import { api_getListDict } from "@/request/apis/assistantApi";
	import router from "@/router";
	import UserInfoHelper from "@/type/utils/UserInfoHelper";
	import { ScheduleTypeVO } from "@/type/vo/ScheduleTypeVO";
	import { ScheduleShiftVO } from "@/type/vo/ScheduleShiftVO";


	const route = useRoute();

	console.log('route', route);
	console.log('route.query', route.query);
	console.log('route.params', route.params);
	const userIdPara = route.query.userId as string;

	const data = reactive({
		listScheduleType: Array<ScheduleTypeVO>(),
		listScheduleShift: Array<ScheduleShiftVO>(),
		userId: userIdPara,
		userInfo: {} as UserInfoVO,
		listTitle: Array<DictInfoVO>(),
		listLevel: Array<DictInfoVO>(),
		listPosition: Array<DictInfoVO>(),
	})


	const pager1 = reactive({
		currentPage: 1,
		pageSize: 10,
		total: 10,
	})
	const pager2 = reactive({
		currentPage: 1,
		pageSize: 10,
		total: 10,
	})
	onMounted(async () => {
		await queryDict(DICT_TYPE_TITLE);
		await queryDict(DICT_TYPE_LEVEL);
		await queryDict(DICT_TYPE_POSITION);
		await search_pri();
	})

	const queryDict = async (dictType : string) => {
		let r = await api_getListDict(dictType);
		if (!r) {
			await msg.error("数据异常");
			return;
		}
		if (r.code != 0) {
			await msg.error(`数据异常${r.code} msg：${r.msg}`);
			return;
		}
		switch (dictType) {
			case DICT_TYPE_TITLE:
				data.listTitle = r.data;
				break;
			case DICT_TYPE_LEVEL:
				data.listLevel = r.data;
				break;
			case DICT_TYPE_POSITION:
				data.listPosition = r.data;
				break;
		}
	}

	const click_back = () => {
		router.back();
	}


	const search_pri = async () => {

		const limit = 10;
		const page = 1;
		const query : UserQueryDto = {
			limit: limit,
			page: page,
			userId: userIdPara
		}

		const r = await api_getListUser(query);
		if (!r) {
			await msg.info('数据异常');
			return;
		}
		if (r.code != 0) {
			await msg.info(`数据异常!  ${r.code} msg：${r.msg}`);
			return;
		}
		if (r.data != undefined) {
			console.log('r.data.records', r.data.records);
			if (r.data.records) {
				for (let i = 0; i < r.data.records.length; i++) {
					r.data.records[i].index = i + 1;
				}
			}
			data.userInfo = r.data.records[0];
			UserInfoHelper.init(data.userInfo);
			UserInfoHelper.initLevel(data.userInfo, data.listLevel);
			UserInfoHelper.initTitle(data.userInfo, data.listTitle);
			UserInfoHelper.initPosition(data.userInfo, data.listPosition);
		}
	}

	const click_edit = (index : number, row : ScheduleTypeVO) => {
		try {
			// //跳转到创建
			// // router.push('/addTrainView');
			// addDialog({
			//   title: "签到码",
			//   component: shallowRef(TrainSignDialog),
			//   width: "600px",
			//   props: {
			//     trainId: row.trainingId,
			//     trainName: row.trainingName,
			//   },
			//   callBack: (dRet: boolean, examId: string) => {
			//
			//   }
			// })
		} catch (error) {
			// 处理取消操作
		}
	}
	const click_delete = (index : number, row : ScheduleTypeVO) => {
		try {
			// //跳转到创建
			// // router.push('/addTrainView');
			// addDialog({
			//   title: "签到码",
			//   component: shallowRef(TrainSignDialog),
			//   width: "600px",
			//   props: {
			//     trainId: row.trainingId,
			//     trainName: row.trainingName,
			//   },
			//   callBack: (dRet: boolean, examId: string) => {
			//
			//   }
			// })
		} catch (error) {
			// 处理取消操作
		}
	}
	const click_search = async () => {
		await search_pri();
	};

	const handleSizeChange = async (val : number) => {
		await search_pri();
	}
	const handleCurrentChange = async (val : number) => {
		await search_pri();
	}
</script>

<style scoped>
	.user_image {
		width: 150px;
		height: 150px;

	}

	.user_userName {
		font-size: 24px;
		font-weight: 600;
		color: #0A1629;
		line-height: 28px;
		margin-top: 32px;
	}

	.user_userId {
		font-size: 16px;
		font-weight: 400;
		color: rgba(0, 0, 0, 0.9);
		line-height: 24px;
		margin-top: 16px;
	}

	.user_title_rec {
		width: 4px;
		height: 28px;
		background: #3F8CFF;
		border-radius: 2px 2px 2px 2px;
		opacity: 1;
	}

	.user_title {
		font-size: 20px;
		font-weight: 400;
		color: #0A1629;
		line-height: 23px;
		margin-left: 8px;
	}

	.form_item {
		margin-top: 16px;
	}


	.grid-container {
		display: grid;
		grid-template-rows: auto 1fr auto;
		height: 100%;
	}

	.row {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.row-1,
	.row-3 {}

	.row-2 {
		overflow: auto;
	}

	.scrollable-content {

		line-height: 1.5em;
	}


	.title {
		font-size: 24px;
		font-weight: 600;
		color: #0A1629;
		line-height: 28px;
	}

	.back_title {
		font-size: 16px;
		font-weight: 600;
		color: #3F8CFF;
		line-height: 19px;
	}

	.user_data {
		font-size: 14px;
		font-weight: 400;
		color: rgba(0, 0, 0, 0.9);
		margin-left: 16px;
	}

	.date-picker {
		height: 48px;
		color: black;
		background: #FFFFFF;
		border-radius: 8px 8px 8px 8px;
		opacity: 1;
		border: 1px solid #DCDCDC;
	}

	.el-scrollbar__view {
		height: calc(100% - 100px);
		/* 根据实际情况调整高度 */
	}

	.infinite-list {
		padding: 0;
		margin: 0;
		list-style: none;
	}

	.infinite-list .infinite-list-item {
		display: flex;
		align-items: center;
		justify-content: center;
		background: black;
		margin: 10px;
		color: var(--el-color-primary);
		overflow: hidden;
	}

	.infinite-list .infinite-list-item+.list-item {
		margin-top: 10px;
	}

	.naireName {
		font-size: 20px;
		font-weight: 400;
		color: #0A1629;
		line-height: 24px;
	}
</style>